#!/usr/bin/env python
# encoding: utf-8
'''
@author: zhaowenpeng
@contact: winston@peipeiyun.com
@software: garner
@file: init_tables.py
@time: 2020/7/22 5:09 下午
@desc:
'''

import os
from sanic.config import Config
import traceback

def load_config():
    conf  = Config()
    module = os.environ.get('SANIC_SETTINGS_MODULE', 'settings')
    if module:
        path = '%s.py' % module.replace('.', '/')
        conf.from_pyfile(path)
    return conf
from loguru import logger
loginfo = logger.bind(user="info")
fmt = "{time:YYYY-MM-DD at HH:mm}-{name}-{level}-{message}\n{exception}"#"{time:YYYY-MM-DD}{level}{message}"
loginfo.add("log/{time:YYYY-MM-DD}.log",format=fmt,  enqueue=True, backtrace=True, diagnose=True)
# logger.add("log/error/{time:YYYY-MM-DD}.log",format=fmt, enqueue=True, backtrace=True, diagnose=True,level="ERROR")


from .client import Client
def func(name,app,url='',body=None):
    try:
        print(name,url,body)
        if name == 'notify_app_service':
            print(url,body)
            Client().cli().post(url,app=app,data=None)
            print('-------注册服务--------')
    except:
        logger.error(traceback.format_exc())
